class Solution {
public:
    int mySqrt(int x) {
        if(x <= 1) // 看给的范围处理边界
        {
            return x / 1; // 如果是1的话下面right就是0了
        }
        int left = 0, right = x / 2;
        while(left < right)
        {
            long long mid = left + (right - left + 1) / 2;
            if(mid * mid > x) // 开long long防溢出
            {
                right = mid - 1;
            }
            else
            {
                left = mid;
            }
        }
        return right;
    }
};